#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long ll;
const int N = 250005, bit = 21;
int n, m, cnt, top, f[bit][N], w[bit][N], dfn[N], h[N], stk[N], dep[N];
int e_cnt, v_cnt, heads[N], vheads[N];
bool key[N];

struct Edge {
  int v, nxt, w;
} e[N << 2], g[N << 2];

inline void add(int u, int v, int w, int *heads, Edge *e, int &cnt) {
  e[++cnt].v = v, e[cnt].nxt = heads[u], heads[u] = cnt, e[cnt].w = w;
}

void dfs(int x) {
  dfn[x] = ++cnt;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != f[0][x]) {
      f[0][v] = x;
      w[0][v] = e[i].w;
      dep[v] = dep[x] + 1;
      dfs(v);
    }
  }
}

inline bool cmp(int x, int y) { return dfn[x] < dfn[y]; }

inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  for (int i = bit - 1; ~i; --i) {
    if (dep[f[i][x]] >= dep[y]) x = f[i][x];
  }
  if (x == y) return x;
  for (int i = bit - 1; ~i; --i)
    if (f[i][x] != f[i][y]) x = f[i][x], y = f[i][y];
  return f[0][x];
}

inline void link(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  int t = x, tmp = 0x7fffffff;
  for (int i = bit - 1; ~i; --i) {
    if (dep[f[i][x]] >= dep[y]) tmp = std::min(tmp, w[i][x]), x = f[i][x];
  }
  add(y, t, tmp, vheads, g, v_cnt);
}

ll solve(int x) {
  ll sum = 0;
  for (int i = vheads[x], v; i; i = g[i].nxt) {
    if (key[v = g[i].v])
      sum += g[i].w, solve(v = g[i].v);
    else
      sum += std::min(solve(v), (ll)g[i].w);
  }
  key[x] = false;
  return sum;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("VirtualTree.in", "r", stdin);
  freopen("VirtualTree.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1, u, v, w; i < n; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    add(u, v, w, heads, e, e_cnt), add(v, u, w, heads, e, e_cnt);
  }
  memset(w, 0x7f, sizeof(w));
  dep[1] = 1;
  dfs(1);
  for (int i = 1; i < bit; ++i) {
    for (int j = 1; j <= n; ++j)
      f[i][j] = f[i - 1][f[i - 1][j]],
      w[i][j] = std::min(w[i - 1][f[i - 1][j]], w[i - 1][j]);
  }
  scanf("%d", &m);
  for (int i = 1, k; i <= m; ++i) {
    scanf("%d", &k);
    v_cnt = 0;
    for (int j = 1; j <= k; ++j) scanf("%d", &h[j]), key[h[j]] = true;
    std::sort(h + 1, h + k + 1, cmp);
    stk[top = 1] = 1;
    vheads[1] = 0;
    for (int j = 1; j <= k; ++j) {
      int mlca = LCA(h[j], stk[top]);
      if (mlca != stk[top]) {
        while (dfn[mlca] < dfn[stk[top - 1]])
          link(stk[top], stk[top - 1]), --top;
        if (dfn[mlca] != dfn[stk[top - 1]])
          vheads[mlca] = 0, link(mlca, stk[top]), stk[top] = mlca;
        else
          link(mlca, stk[top--]);
      }
      vheads[h[j]] = 0, stk[++top] = h[j];
    }
    for (int j = 1; j < top; ++j) link(stk[j + 1], stk[j]);
    printf("%lld\n", solve(stk[1]));
  }
  return 0;
}